﻿using System;
using System.Collections.Generic;
using System.Text;
using Calculations.Calculations;

namespace Calculations
{
    public class Vector : IEquatable<Vector>
    {
        private double x;

        public double X
        {
            get { return x; }
            set { x = value; }
        }

        private double y;

        public double Y
        {   
            get { return y; }
            set { y = value; }
        }

        public double Length
        {
            get
            {
                return Math.Sqrt(Math.Pow(this.X, 2) + Math.Pow(this.Y, 2));
            }
            set
            {
                double length = this.Length;
                this.X = this.X * value / length;
                this.Y = this.Y * value / length;
            }
        }

        public Vector()
        {
        }

        public Vector(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public Vector Normalize()
        {
            Vector result = new Vector(this.X, this.Y);
            result.Length = 1;
            return result;
        }

        public Vector Multiply(double number)
        {
            Vector multiplyVector = new Vector(this.X * number, this.Y * number);
            return multiplyVector;
        }

        #region IEquatable<Vector> Members

        public bool Equals(Vector other)
        {
            if (GeometryCalculations.IsEqual(this.X, other.X, 0.000001) && GeometryCalculations.IsEqual(this.Y, other.Y, 0.000001))
                return true;
            else
                return false;
        }

        #endregion
    }
}
